import collections


class Solution(object):
    def isDecomposable(self, s):
        n = len(s)
        left = 0
        right = 0
        d = collections.defaultdict(int)
        while right < n:
            if s[right] != s[left]:
                d[right - left] += 1
                left = right
            right += 1
        d[right - left] += 1
        ans = 0
        for key in d:
            if key % 3 == 2:
                ans += d[key]
            if key % 3 == 1:
                return False
        return ans == 1

data = Solution()
s = "00011111222"
print(data.isDecomposable(s))